package com.letoken.platform.app.controller;

import com.alibaba.fastjson.JSONObject;
import com.letoken.platform.repo.app.po.AppUserIssue;
import com.letoken.platform.repo.app.po.AppUserTeam;
import com.letoken.platform.repo.wallet.constant.AppRabbitConstant;
import com.letoken.platform.repo.wallet.req.WithdrawReq;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import com.letoken.platform.app.service.AppUserIssueService;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class RabbitMQConsumer {

    @Autowired
    private AppUserIssueService appUserIssueService;

    @RabbitListener(queues = AppRabbitConstant.QUEUE_USER_TEAM_DYNAMIC_REWARD)
    @RabbitHandler
    void rechargeConfirmDelay(@Payload String message) {
        AppUserTeam req = JSONObject.parseObject(message, AppUserTeam.class);
        if(StringUtils.isEmpty(req) || null == req.getUserId()){
            return;
        }
        appUserIssueService.ecologicalRewards(req);
    }
}
